﻿Imports MICROFORMA.BEL
Imports MICROFORMA.DIL
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports System.Data.Common
Imports System.Data

Public Class RepositorioDA
    Implements DIL.RepositorioDI


    Public Function Add(ByVal _RepositorioBE As BEL.RepositorioBE) As String Implements DIL.RepositorioDI.Add
        Dim db As Database = DatabaseFactory.CreateDatabase()

        Try
            Dim query As String = "Insert into Repositorio (Nombre,RutaInicio,ConnectionString,RutaDocumentos,TipoBD,Online)" _
                                    & "Values (" & _RepositorioBE.Nombre & ",'" & _RepositorioBE.RutaInicio _
                                    & "','" & _RepositorioBE.ConnectionString & "'," & _RepositorioBE.RutaDocumentos _
                                    & "','" & _RepositorioBE.TipoBD & "'," & _RepositorioBE.Online & "','" & ")"


            Dim o_dbCommand As DbCommand = db.GetSqlStringCommand(query)


            db.ExecuteNonQuery(o_dbCommand)


            Return "OK"

        Catch ex As Exception

            Return ex.Message.ToString

        End Try
    End Function

    Public Function GetList() As DataTable Implements DIL.RepositorioDI.GetList

        Dim db As Database = DatabaseFactory.CreateDatabase()

        Dim query As String = "select * from repositorio where online = 1"

        Dim dbCommand As DbCommand = db.GetSqlStringCommand(query)

        Dim productsDataSet As DataSet = Nothing

        productsDataSet = db.ExecuteDataSet(dbCommand)


        Return productsDataSet.Tables(0)

    End Function
End Class
